package processor;

import model.BaseRegisterInfo;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.selector.Selectable;
import util.MyString;
import util.Mytime;

import java.util.List;

public class BasePageRegisterProcessor {
    /**
     * @Description 处理香港公司的情况
     * @param page
     * @return
     */
    public static void ParseBRI(Page page){
        BaseRegisterInfo baseRegisterInfo = new BaseRegisterInfo();
        String unique = page.getRequest().getExtra("unique").toString();
        baseRegisterInfo.setCompany_unique(unique);//公司url
        baseRegisterInfo.setSearch_word(page.getRequest().getExtra("company_name").toString());//当前搜索词
        baseRegisterInfo.setCompany_name(MyString.Replace(page.getRequest().getExtra("company_name").toString()));
        page.putField("company_name",page.getRequest().getExtra("company_name").toString());
        baseRegisterInfo.setOffical_url("");
        List<Selectable> node = page.getHtml().xpath("//section[@id='registerInfo']//table[@class=\"ntable\"]//td[@class!=\"tb\"]").nodes();
        if(node.size()>0){
            baseRegisterInfo.setCompany_full_name(MyString.Replace(node.get(0).xpath("/td/allText()").toString()));
            baseRegisterInfo.setShareholder(node.get(1).xpath("/td/allText()").toString());
            baseRegisterInfo.setSharehold(node.get(2).xpath("/td/allText()").toString());
            baseRegisterInfo.setCompany_number(node.get(3).xpath("/td/allText()").toString());
            baseRegisterInfo.setCompany_type(node.get(4).xpath("/td/allText()").toString());
            baseRegisterInfo.setEstablishment_date(node.get(5).xpath("/td/allText()").toString());
            baseRegisterInfo.setOperating_status(node.get(6).xpath("/td/allText()").toString());
            baseRegisterInfo.setNote(node.get(7).xpath("/td/allText()").toString());
            baseRegisterInfo.setWind_up_mode(node.get(8).xpath("/td/allText()").toString());
            baseRegisterInfo.setFucked_up_date(node.get(9).xpath("/td/allText()").toString());
            baseRegisterInfo.setRegister_of_charges(node.get(10).xpath("/td/allText()").toString());
            baseRegisterInfo.setImportant_things(node.get(11).xpath("/td/allText()").toString());
            baseRegisterInfo.setCreatedTime(Mytime.getTime());
        }
        page.putField("BaseRegisterInfo",baseRegisterInfo);
    }
}
